package com.nail.api.customMake.service.impl;

import com.nail.api.customMake.bean.GoodsPrice;
import com.nail.api.customMake.dao.IGoodsPriceDao;
import com.nail.api.customMake.service.IGoodsPriceService;
import com.nail.service.impl.BaseService;
import com.nail.utils.PageResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by jie on 2017/9/17.
 */
@Service("goodsPriceService")
public class GoodsPriceServiceImpl extends BaseService implements IGoodsPriceService {
    Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    IGoodsPriceDao goodsPriceDao;

    @Transactional
    public boolean addGoodsPrice(GoodsPrice goodsPrice) {
    	GoodsPrice gp = goodsPriceDao.getGoodsPricesByType(goodsPrice.getType());
        if(gp != null){
            return false;
        }
        goodsPriceDao.insertSelective(goodsPrice);
        return true;
    }

    @Transactional
    public boolean updateGoodsPrice(GoodsPrice goodsPrice) {
        GoodsPrice gp = goodsPriceDao.selectByIdAndType(goodsPrice.getId(),goodsPrice.getType());
        if(gp != null){
            return false;
        }
        goodsPriceDao.updateByPrimaryKeySelective(goodsPrice);
        return true;
    }

    @Transactional
    public void deleteGoodsPrice(Long id) {
        goodsPriceDao.deleteByPrimaryKey(id);
    }

    public List<GoodsPrice> getGoodsPrices(PageResult pageResult) {
        return goodsPriceDao.getGoodsPrices(pageResult.getBegin(), pageResult.getPageSize());
    }

    public GoodsPrice getGoodsPricesById(Long id){
        return goodsPriceDao.selectByPrimaryKey(id);
    }

    @Transactional
    public void setIsAble(Long id,Integer isAble){
        goodsPriceDao.setIsAble(id,isAble);
    }

    public GoodsPrice getGoodsPricesByType(Integer type){
        return goodsPriceDao.getGoodsPricesByType(type);
    }
}
